package com.jianbing.entity;

import com.alibaba.fastjson.annotation.JSONField;
import com.jianbing.annotation.NotMongoField;
import com.jianbing.util.TaskHelper;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import java.util.Date;

/**
 * Created by Han, Tixiang on 2016/8/25 0025.
 */
public abstract class Task {
    @NotMongoField
    private static final Log log = LogFactory.getLog(Task.class);
    @JSONField(ordinal = 1)
    private int id;
    @JSONField(ordinal = 3)
    private Integer currentStep;
    @JSONField(format = "yyyy-MM-dd HH:mm:ss", ordinal = 99)
    private Integer notifyState;
    @JSONField(format = "yyyy-MM-dd HH:mm:ss", ordinal = 14)
    private Object nodeId;
    @JSONField(format = "yyyy-MM-dd HH:mm:ss", ordinal = 99)
    private boolean isTimeout = false;
    @JSONField(serialize = false)
    @NotMongoField
    private long timeout;  //task超时  单位：秒
    @JSONField(ordinal = 2)
    private Integer cityId;
    @JSONField(ordinal = 3)
    private Integer state = TaskHelper.NEW;
    @JSONField(format = "yyyy-MM-dd HH:mm:ss", ordinal = 100)
    private String callbackUrl;
    @JSONField(format = "yyyy-MM-dd HH:mm:ss", ordinal = 9)
    private String ip;
    @JSONField(format = "yyyy-MM-dd HH:mm:ss", ordinal = 9)
    private String note;
    @JSONField(ordinal = 5)
    private String data;
    @JSONField(format = "yyyy-MM-dd HH:mm:ss", ordinal = 6)
    private Date createDate;
    @JSONField(format = "yyyy-MM-dd HH:mm:ss", ordinal = 7)
    private Date dispatchDate;
    @JSONField(format = "yyyy-MM-dd HH:mm:ss", ordinal = 8)
    private Date endDate;
    @JSONField(format = "yyyy-MM-dd HH:mm:ss", ordinal = 99)
    private Date notifyDate;

    public void setNotifyDate(Date notifyDate) {
        this.notifyDate = notifyDate;
    }

    public void setNotifyState(Integer notifyState) {
        this.notifyState = notifyState;
    }

    public Date getNotifyDate() {
        return notifyDate;
    }

    public Integer getCurrentStep() {
        return currentStep;
    }

    public void setCurrentStep(Integer currentStep) {
        this.currentStep = currentStep;
    }

    private String city;

    public void setCityId(Integer cityId) {
        this.cityId = cityId;
    }

    public Integer getCityId() {
        return cityId;
    }

    public Integer getNotifyState() {
        return notifyState;
    }

    public boolean getIsTimeout() {
        return isTimeout;
    }

    public void setIsTimeout(boolean timeout) {
        this.isTimeout = timeout;
    }

    public Object getNodeId() {
        return nodeId;
    }

    public void setTimeout(long timeout) {
        this.timeout = timeout;
    }

    public long getTimeout() {
        return timeout;
    }

    public Task() {
    }

    public void setData(String data) {
        this.data = data;
    }

    public String getData() {
        return data;
    }

    public String getCity() {
        return city;
    }

    public void setCity(String city) {
        this.city = city;
    }

    public Task(int taskId) {
        this.id = taskId;
    }

    public Integer getState() {
        return state;
    }

    public void setState(Integer state) {
        this.state = state;
    }

    public void setId(int id) {
        this.id = id;
    }

    public void setCallbackUrl(String callbackUrl) {
        this.callbackUrl = callbackUrl;
    }

    public int getId() {
        return id;
    }

    public String getCallbackUrl() {
        return callbackUrl;
    }

    public void setIp(String ip) {
        this.ip = ip;
    }

    public void setNote(String note) {
        this.note = note;
    }

    public void setCreateDate(Date createDate) {
        this.createDate = createDate;
    }

    public void setDispatchDate(Date dispatchDate) {
        this.dispatchDate = dispatchDate;
    }

    public void setEndDate(Date endDate) {
        this.endDate = endDate;
    }

    public String getIp() {
        return ip;
    }

    public String getNote() {
        return note;
    }

    public Date getCreateDate() {
        return createDate;
    }

    public Date getDispatchDate() {
        return dispatchDate;
    }

    public Date getEndDate() {
        return endDate;
    }

    public void setNodeId(Object nodeId) {
        this.nodeId = nodeId;
    }

    public void reset() {
        this.setDispatchDate(null);
        this.setNodeId(null);
        this.setTimeout(0);
    }

    public String toString() {
        return ToStringBuilder.reflectionToString(this, ToStringStyle.SHORT_PREFIX_STYLE);
    }
}
